<template>
  <div class="page">
    <headerbar>动态</headerbar>
    <section class="inner-content" v-if="preData">
      <section class="detail">
        <h1 class="title">{{preData.title}}</h1>
        <p class="date">来源：{{preData.source || '未知'}} <span class="float-right">时间：{{preData.createTime}}</span></p>
        <p class="color-red pdh-2 pdv-1 shortTitle">{{preData.shortTitle}}</p>
        <p class="line"></p>
        <div class="cont-text" v-if="data.newsContentExt" v-html="data.newsContentExt.contents">
        </div>
        <p class="pdv-2"></p>
        <viewsUpsComponent :detail="preData"></viewsUpsComponent>

      </section>
    </section>

    <p class="pdv-10"></p>
    <p class="pdv-3"></p>

    <liveMsgComponent v-if="preData.id" :detail="preData" :contentId="data.newsContentExt.contentId" :comments="data.newsContentExt.contents"></liveMsgComponent>

  </div>
</template>

<script>
  import tools from '@/utils/tools'
  import loginService from '@/service/loginService'
  import liveMsgComponent from '@/components/common/liveMsgComponent'
  import viewsUpsComponent from '@/components/common/viewsUpsComponent'
  export default {
    components: {liveMsgComponent, viewsUpsComponent},
    name: 'workingTrendsDetail',
    data () {
      return {
        preData: {},
        data: {},
        id: ''
      }
    },
    created () {
      this.preData = this.$store.state.newsDetail
      this.id = this.$route.params.id
      this.$store.state.flagType = 1
      this.loadData()
      this.like(this.id)
    },
    methods: {
      loadData () {
        loginService.contentDetail(this.id).then((res) => {
          if (res.code !== 0) {
            return tools.tip(res.message)
          }
          this.data = res.data
          console.log('this.data=', this.data)
          console.log('this.data.newsContentExt=', this.data.newsContentExt)
          this.historyAdd()
        })
      },
      collection () {
        let data = {
          contentId: this.data.newsContentExt.contentId
        }
        loginService.addCollection(data).then((res) => {
          if (res.code !== 0) {
            return tools.tip(res.message)
          }
          tools.tip('收藏成功！')
        })
      },
    // 添加到我的足迹
      historyAdd () {
        let data = {
          contentId: this.data.newsContentExt.contentId,
          newsType: 0,  // 新闻类型(0图文;1长视频;2音频;3短视频)
        }
        loginService.historyAdd(data).then((res) => {
        })
      },
      like (id) {
        let params = {
          contentId: id,
          type: 1
        }
        this.fetchService.updateCount(params).then(res => {
        })
      }
    }
  }
</script>

<style scoped>

</style>
